ui/cocoa.m: adds Machine menu with pause and resume menu items
PATCH 1/3 ui/cocoa.m: adds Machine menu with pause and resume menu items
Adds a Machine menu to the Macintosh interface that pause and resume menu items. These items can either pause or resume execution of the guest operating system.
--- ui/cocoa.m | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 79 insertions(+), 0 deletions(-)
ui/cocoa.m +79 -0
@@ -29,6 +29,7 @@ #include "ui/console.h" #include "ui/input.h" #include "sysemu/sysemu.h" +#include "qmp-commands.h" #ifndef MAC_OS_X_VERSION_10_4 #define MAC_OS_X_VERSION_10_4 1040
@@ -64,6 +65,7 @@ static int last_buttons; int gArgc; char **gArgv; +NSTextField * pauseLabel; // keymap conversion int keymap[] =
@@ -801,6 +803,10 @@ QemuCocoaView *cocoaView; - (void)toggleFullScreen:(id)sender; - (void)showQEMUDoc:(id)sender; - (void)showQEMUTec:(id)sender; +- (void)pauseQemu:(id)sender; +- (void)resumeQemu: (id) sender; +- (void)displayPause; +- (void)removePause; @end @implementation QemuCocoaAppController
@@ -833,6 +839,17 @@ QemuCocoaView *cocoaView; [normalWindow makeKeyAndOrderFront:self]; [normalWindow center]; + /* Used for displaying pause on the screen */ + pauseLabel = [NSTextField new]; + [pauseLabel setBezeled:YES]; + [pauseLabel setDrawsBackground:YES]; + [pauseLabel setBackgroundColor: [NSColor whiteColor]]; + [pauseLabel setEditable:NO]; + [pauseLabel setSelectable:NO]; + [pauseLabel setStringValue: @"Paused"]; + [pauseLabel setFont: [NSFont fontWithName: @"Helvetica" size: 90]]; + [pauseLabel setTextColor: [NSColor blackColor]]; + [pauseLabel sizeToFit]; } return self; }
@@ -943,6 +960,44 @@ QemuCocoaView *cocoaView; [[NSWorkspace sharedWorkspace] openFile:[NSString stringWithFormat:@"%@/../doc/qemu/qemu-tech.html", [[NSBundle mainBundle] resourcePath]] withApplication:@"Help Viewer"]; } + +/* Pause the guest */ +- (void)pauseQemu:(id)sender +{ + qmp_stop(NULL); + [sender setEnabled: NO]; + [[[sender menu] itemWithTitle: @"Resume"] setEnabled: YES]; + [self displayPause]; +} + +/* Resume running the guest operating system */ +- (void)resumeQemu: (id) sender +{ + qmp_cont(NULL); + [sender setEnabled: NO]; + [[[sender menu] itemWithTitle: @"Pause"] setEnabled: YES]; + [self removePause]; +} + +/* Displays the word pause on the screen */ +- (void)displayPause +{ + /* Coordinates have to be calculated each time because the window can change its size */ + int xCoord, yCoord, width, height; + xCoord = ([normalWindow frame].size.width - [pauseLabel frame].size.width)/2; + yCoord = [normalWindow frame].size.height - [pauseLabel frame].size.height - ([pauseLabel frame].size.height * .5); + width = [pauseLabel frame].size.width; + height = [pauseLabel frame].size.height; + [pauseLabel setFrame: NSMakeRect(xCoord, yCoord, width, height)]; + [cocoaView addSubview: pauseLabel]; +} + +/* Removes the word pause from the screen */ +- (void)removePause +{ + [pauseLabel removeFromSuperview]; +} + @end
@@ -1039,7 +1094,28 @@ int main (int argc, const char * argv[]) { return 0; } +#pragma mark machine menu code +/* + Adds the Machine menu to the menu bar. + Has to be added separately because QEMU needs + to be running to determine used items. +*/ +static void createMachineMenu() +{ + NSMenu * menu; + NSMenuItem * menuItem; + + // Machine menu + menu = [[NSMenu alloc] initWithTitle: @"Machine"]; + [menu setAutoenablesItems: NO]; + [menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Pause" action: @selector(pauseQemu:) keyEquivalent: @""] autorelease]]; + [menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Resume" action: @selector(resumeQemu:) keyEquivalent: @""] autorelease]]; + menuItem = [[[NSMenuItem alloc] initWithTitle: @"Machine" action:nil keyEquivalent:@""] autorelease]; + [menuItem setSubmenu:menu]; + [[NSApp mainMenu] insertItem: menuItem atIndex: 2]; // Insert after View menu + [[menu itemWithTitle: @"Resume"] setEnabled: NO]; // Disables the Resume menu item because it isn't needed right now. +} #pragma mark qemu static void cocoa_update(DisplayChangeListener *dcl,
@@ -1128,4 +1204,7 @@ void cocoa_display_init(DisplayState *ds, int full_screen) // register cleanup function atexit(cocoa_cleanup); + + // Creates and adds the Machine menu to the menubar + createMachineMenu(); }
Signature · 1 line
1.7.5.4
Quoted 1 line · Programmingkid
Adds a Machine menu to the Macintosh interface that pause and resume menu
"with pause and resume menu items"
Quoted 5 lines
items.
These items can either pause or resume execution of the guest operating system.Signed-off-by John Arbuckle <[email protected]>
This mostly looks good. A minor note: your commit messages would fit better with the usual style if you phrased them as "Add foo", "Improve bar", etc, rather than "Adds", "Improves", etc. Wrapping lines between 70-75 characters would be nice too (you can see the lines have wrapped badly above, for instance).
Could you rebase these patches on top of my cocoa.next branch, please?
Quoted 20 lines
--- ui/cocoa.m | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 79 insertions(+), 0 deletions(-)ui/cocoa.m +1
-0@@ -29,6 +29,7 @@ #include "ui/console.h" #include "ui/input.h" #include "sysemu/sysemu.h" +#include "qmp-commands.h"#ifndef
MAC_OS_X_VERSION_10_4
#defineMAC_OS_X_VERSION_10_41040
ui/cocoa.m static int last_buttons; · line 70
Quoted 6 lines
ui/cocoa.m +1
-0@@ -64,6 +65,7 @@ static int last_buttons; int gArgc; char **gArgv; +NSTextField * pauseLabel;
No need for a space after the '*'.
ui/cocoa.m QemuCocoaView *cocoaView; · line 807
Quoted 8 lines
ui/cocoa.m +0
-0// keymap conversionint keymap[] =
ui/cocoa.m +2
-0@@ -801,6 +803,10 @@ QemuCocoaView *cocoaView; - (void)toggleFullScreen:(id)sender; - (void)showQEMUDoc:(id)sender; - (void)showQEMUTec:(id)sender; +- (void)pauseQemu:(id)sender; +- (void)resumeQemu: (id) sender;
Style nit -- can you be consistent with the spacing here? Also QEMU should be all-caps.
ui/cocoa.m int main (int argc, const char * argv[]) { · line 1103
Quoted 5 lines
ui/cocoa.m +5
-0+/* + Adds the Machine menu to the menu bar. + Has to be added separately because QEMU needs + to be running to determine used items. +*/
/* This is the usual
* format for comments that
* span multiple lines.
*/
Quoted 16 lines
ui/cocoa.m +9
-0+static void createMachineMenu() +{ + NSMenu * menu; + NSMenuItem * menuItem; + + // Machine menu + menu = [[NSMenu alloc] initWithTitle: @"Machine"]; + [menu setAutoenablesItems: NO]; + [menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Pause" action:@selector(pauseQemu:) keyEquivalent: @""] autorelease]];
+ [menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Resume" action:
@selector(resumeQemu:) keyEquivalent: @""] autorelease]];
+ menuItem = [[[NSMenuItem alloc] initWithTitle: @"Machine" action:nil
keyEquivalent:@""] autorelease];ui/cocoa.m +2
-0+ [menuItem setSubmenu:menu]; + [[NSApp mainMenu] insertItem: menuItem atIndex: 2]; // Insert after
Quoted 4 lines
View menu
+ [[menu itemWithTitle: @"Resume"] setEnabled: NO]; // Disables the
Resume menu item because it isn't needed right now. +}
If we use the approach I described in the previous patch where all the static parts of menus are created initially and then dynamic parts added later, we can do this all in the same place as the other menus are created.
thanks
-- PMM